package com.augurit.gzcgwsp.ssylb.dao;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import org.springside.modules.orm.hibernate.SimpleHibernateDao;

import com.augurit.gzcgwsp.rqqyjyxk.entity.YwPrintRqRqssylb;
import com.augurit.gzcgwsp.ssylb.entity.YwRqRqssylb;

@Repository
public class YwRqRqssylbDao extends SimpleHibernateDao<YwRqRqssylb, Long> {
	/**
	 * 根据案件Id查找excel表格的存放路径
	 * @param id
	 * @return
	 */
	public String findFilePath(Long id){
		String sql="select t.filepath from yw_com_sjcl t, yw_com_aj_cl l where l.clid=t.id and l.tplcode='rqjyxkz_pzqy' and  l.ajid='"+id+"'";
		String filepath=null;
		List list=this.getSession().createSQLQuery(sql).list();
		if(list!=null && list.size()>0)
		{
			filepath=(String)list.get(0);
			
		}
		return filepath;
	}
	/**
	 * 根据案件Id删除所有设施信息
	 * @param id
	 * @return
	 */
	public int deleteAll(Long id){
		String sql="delete from yw_rq_rqssylb t where t.qyjyxkid="+id;
		int flag=this.getSession().createSQLQuery(sql).executeUpdate();
		return flag;
	}
	public YwRqRqssylb findById(Long id){
		String sql="from YwRqRqssylb t where t.ssylbid="+id;
		YwRqRqssylb ssylb=null;
		List list=this.getSession().createQuery(sql).list();
		if(list!=null&&list.size()>0)
		{
			ssylb =(YwRqRqssylb)list.get(0);
		}
		return ssylb;
	}
	
	/**
	 * 打印表中的设施数据实体
	 * @param id
	 * @return
	 */
	public YwPrintRqRqssylb getPrintEntity(Long id) {
		String sql="from YwPrintRqRqssylb t where t.ssylbid="+id;
		YwPrintRqRqssylb ssylb=null;
		List list=this.getSession().createQuery(sql).list();
		if(list!=null&&list.size()>0)
		{
			ssylb =(YwPrintRqRqssylb)list.get(0);
		}
		return ssylb;
	}
	
	/**
	 * 保存设施一览表到打印的表中
	 * @param entity
	 */
	public void savePrintEntity(YwPrintRqRqssylb entity) {
		Session session=this.getSession();
		session.saveOrUpdate(entity);
		
	}
    
}